package com.wang.home.find;

import com.alibaba.fastjson.JSONObject;
import com.wang.home.ExtKey;
import com.wang.home.HomeReq;
import com.wang.tool.dagre.DagreContext;
import com.wang.tool.dagre.node.DagreNode;
import com.wang.tool.dagre.DagreResult;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @Description
 * @Author shaopeng
 * @Date 2021/9/28
 * @Version 1.0
 */
public class SeaFinder implements DagreNode<HomeReq> {
    @Override
    public Collection<String> getDependIds() {
        return FindWorkerEnum.SEA.getDependCodes();
    }

    @Override
    public Object preCheck(DagreContext<HomeReq> context) {
        return null;
    }

    @Override
    public boolean isSync() {
        return false;
    }

    @Override
    public String getId() {
        return FindWorkerEnum.SEA.name();
    }

    @Override
    public Object execute(DagreContext<HomeReq> context) throws Exception {
        CopyOnWriteArraySet<String> items = context.computeIfAbsentRunObj(ExtKey.itemIds, k->new CopyOnWriteArraySet<>());
        List<JSONObject> datas = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            JSONObject d = new JSONObject();
            d.put("itemId", i);
            items.add(String.valueOf(i));
            datas.add(d);
        }
//        Thread.sleep(30);
        return DagreResult.buildSuccess(datas);
//        return datas;
    }
}
